package com.soft.javase.ch10.test.stream;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/5/7
 *10. 将员工按照工资由低到高（工资一样则按年龄由小到大）排序，显示名字
 */
public class SortEmployeesBySalaryThenAge {
    public static void main(String[] args) {
        List<Employee> employees = new ArrayList<>();
        employees.add(new Employee("张三", 25, 7500));
        employees.add(new Employee("李四", 30, 8500));
        employees.add(new Employee("王五", 28, 9000));
        employees.add(new Employee("赵六", 35, 7800));
        employees.add(new Employee("钱七", 26, 7500)); // 相同工资，不同年龄

        System.out.println("员工按工资升序、年龄升序排序:");
        employees.stream()
                .sorted((e1, e2) -> {
                    if (e1.getSalary() != e2.getSalary()) {
                        return (int)(e1.getSalary() - e2.getSalary());
                    } else {
                        return e1.getAge() - e2.getAge();
                    }
                })
                .forEach(e -> System.out.println(e.getName() +
                        ": 工资=" + e.getSalary() + ", 年龄=" + e.getAge()));
    }
}
